<template>
  <div class="box">
    <h2>子组件2</h2>
    <div>弟弟: {{ money }}</div>
    <el-button @click="sendMoney">送钱</el-button>
  </div>
</template>
<script setup>
import { ref } from "vue";

import emmitter from "@/utils/emmiter";
const money = ref(100);
const sendMoney = () => {
  if (money.value > 0) {
    money.value -= 10;
    emmitter.emit("send-money", 10);
  } else {
    ElMessage.error("钱不够了");
    emmitter.off("send-money");
  }
};
</script>
<style lang="less" scoped>
.box {
  background: pink;
  margin-top: 30px;
}
</style>
